
<link rel="stylesheet" type="text/css" href="style.css" />
<?php
	if(empty($_GET['board']) or empty($_GET['customer']) or empty($_GET['business'])) {
		echo "项目参数错误";
		exit;
	}
	if($_GET['board'] == "empty" or $_GET['customer'] == "empty" or $_GET['business'] == "empty") {
		echo "项目参数错误";
		exit;
	}
	require_once("connect_sql.php");
	
	//project table
	$board = $_GET['board'];
	$customer = $_GET['customer'];
	$business = $_GET['business'];
	$project_id = 0;
	$author = "";
	$makefile = "";
	$platform = "";
	$function = "";
	$lcd = "";
	$camera = "";
	$rfpa = "";
	$classK = "";
	$lastVersion = "";
	$lastDate = "";
	$gbVersion = "";
	$ataVersion = "";
	
	$sql = "select * from project where board=\"$board\" and customer=\"$customer\" and business=\"$business\"";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	
	while($row = mysql_fetch_array($result)) {
		$project_id = $row['id'];
		$author = $row['author'];
		$makefile = $row['makefile'];
		$platform = $row['platform'];
		$function = $row['function'];
		$lcd = $row['lcd'];
		$camera = $row['camera'];
		$rfpa = $row['rfpa'];
		$classK = $row['classK'];
		$lastVersion = $row['lastVersion'];
		$lastDate = $row['lastDate'];
		$gbVersion = $row['gbVersion'];
		$ataVersion = $row['ataVersion'];
	}
	
	//platform table
	$code = "";
	$downloadTool = "";
	
	$sql = "select * from platform where id=\"$platform\"";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	while($row = mysql_fetch_array($result)) {
		$platform = $row['name'];
		$code = $row['code'];
		$downloadTool = $row['downloadTool'];
	}
	
	//writeRecord table
	$recordVersion = "";
	
	$sql = "select distinct recordVersion,recordDate from writeRecord where project=\"$project_id\" order by recordDate DESC";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	while($row = mysql_fetch_array($result)) {
		$recordVersion = $row['recordVersion'];
		break;
	}
	
	//author table
	$sql = "select name from author where id=\"$author\"";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	$row = mysql_fetch_array($result);
	$author = $row['name'];
	//customer table
	$sql = "select name from customer where id=\"$customer\"";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	$row = mysql_fetch_array($result);
	$customer = $row['name'];
	//rfpa table
	$sql = "select name from rfpa where id=\"$rfpa\"";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	$row = mysql_fetch_array($result);
	$rfpa = $row['name'];
	//classK table
	$sql = "select name from classK where id=\"$classK\"";
	$result = mysql_query($sql);
	if(!$result) echo mysql_error();
	$row = mysql_fetch_array($result);
	$classK = $row['name'];
?>
<table class="table1">
	<!--<tr bgcolor="#d0d9f4">
		<td>
			<table width="100%" height="42" align="center">
				<td align="left"><font color="blue"><b>用户:</b></font><?php echo $_COOKIE['nickname']?></td>
				<td align="right"><a href="logout.php"><font color="blue">注销</font></a></td>
			</table>
		</td>
	</tr>
	-->
	<tr>
		<td>
			<table class="table2">
				<td class="tdLeft"><input type="hidden" id="project_id" name="project_id" value="<?php echo $project_id;?>"></td>
				<td class="tdLeft"><span>发布人：</span><?php echo $author;?></td>
				<td class="tdCenter"><span>主板型号：</span><?php echo $board;?></td>
				<td class="tdCenter"><span>客户：</span><?php echo $customer;?></td>
				<td class="tdRight"><span>商业型号：</span><?php echo $business;?></td>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table class="table2">
				<tr><td class="tdLeft"><span>平台：</span><?php echo $platform;?></td></tr>
				<tr><td class="tdLeft"><span>代码包名：</span><?php echo $code;?></td></tr>
				<tr><td class="tdLeft"><span>下载工具：</span><?php echo $downloadTool;?></td></tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table class="table2">
				<tr>
					<td class="td2"><span>最新软件版本：</span><?php echo $lastVersion;?></td>
					<td class='td2'><span>时间：</span><?php echo $lastDate;?></td>
				</tr>
				<tr><td class="td2"><span>上次量产版本：</span><?php echo $recordVersion;?></td></tr>
				<tr><td class="td2"><span>ATA软件版本：</span><?php echo $ataVersion;?></td></tr>
				<tr><td class="td2"><span>本次填单版本：</span><input type="text" autocomplete="off" id="version" name="recordVersion" list="versions"></td></tr>
					<datalist id="versions">
					<?php
						$sql = "select distinct recordVersion from writeRecord where project='$project_id' order by recordDate DESC";
						$result = mysql_query($sql);
						if($result) {
							while($row = mysql_fetch_array($result)) {
								printf("<option value=\"%s\">", $row['recordVersion']);
							}
						} else {
							echo mysql_error();
						}
					?>
					</datalist>
				<tr><td class="td2"><span>本次填单数量：</span><input type="text" autocomplete="off" id="quantity" name="quantity"><b>K</b></td></tr>
				<tr><td class="td2"><span>本次填单时间：</span><input type="text" id="date" name="date" value="" readonly="true" onclick="fPopCalendar(date,date);return false"/></td></tr>
			</table>
		</td>	
	</tr>
	<tr>
		<td>
			<table class="table2">
				<td class="td3"><span>软件功能：<br></span>
					<?php 
						$funcArray = explode(',', $function);
						foreach($funcArray as $id) {
							$sql = "select * from function where id=\"$id\" order by id";
							$result = mysql_query($sql);
							if(!$result) {
								echo mysql_error();
							} else {
								while($row = mysql_fetch_array($result)) {
									printf("&nbsp;&nbsp;%s<br>", $row['name']);
								}
							}
						}
					?>
				</td>
				<td class="td3"><span>兼容屏：<br></span>
					<?php 
						$lcdArray = explode(',', $lcd);
						foreach($lcdArray as $id) {
							$sql = "select * from lcd where id=\"$id\" order by id";
							$result = mysql_query($sql);
							if(!$result) {
								echo mysql_error();
							} else {
								while($row = mysql_fetch_array($result)) {
									printf("&nbsp;&nbsp;%s<br>", $row['name']);
								}
							}
						}
					?>
				</td>
				<td class="td3"><span>兼容摄像头：<br></span>
					<?php 
						$cameraArray = explode(',', $camera);
						foreach($cameraArray as $id) {
							$sql = "select * from camera where id=\"$id\" order by id";
							$result = mysql_query($sql);
							if(!$result) {
								echo mysql_error();
							} else {
								while($row = mysql_fetch_array($result)) {
									printf("&nbsp;&nbsp;%s<br>", $row['name']);
								}
							}
						}
					?>
				</td>
				<td class="td3">
					<table>
						<tr><td>
							<span>射频PA：<br></span>
							<?php 
								echo "&nbsp;&nbsp;".$rfpa."<br>";
							?>
						</td></tr>
						<tr><td>
							<span>功放：<br></span>
							<?php 
								echo "&nbsp;&nbsp;".$classK."<br>";
							?>
						</td></tr>
					</table>
				</td>
			</table>
		</td>
	</tr>
	<tr>
		<td align="center"><button class="button updateBtn" onclick="return onWriteProduction(project_id.value, version.value, quantity.value, date.value);">提交</button></td>
	</tr>
	<tr>
		<td class="td4">
			<table id="record"class="table2">
				<tr>
					<td class="td5"></td>
					<?php
						$sql = "select sum(quantity) as num from writeRecord where project=\"$project_id\"";
						$result = mysql_query($sql);
						if(!$result) {
							echo mysql_error();
						} else {
							while($row = mysql_fetch_array($result)) {
								printf("<td class=\"tdLeft\"><span>量产总数：</span>%.1f K</td>", $row['num']);
								break;
							}
						}
					?>
				</tr>
				<?php
					$sql = "select * from writeRecord where project=\"$project_id\" order by recordDate DESC";
					$result = mysql_query($sql);
					if(!$result) {
						echo mysql_error();
					} else {
						$i = 1;
						while($row = mysql_fetch_array($result)) {
							printf("<tr>\n");
							printf("\t<td class='td5'><span>%d.</span></td>\n", $i++);
							printf("\t<td class='td6'>版本：%s</td>\n", $row['recordVersion']);
							printf("\t<td class='td7'>数量：%s</td>\n", $row['quantity']);
							printf("\t<td class='td8'>时间：%s</td>\n", $row['recordDate']);
							printf("\t<td class='td9'><button class='button deleteBtn' onClick='onDeleteRecordClick(%d)'>删除</button></td>\n", $row['id']);
							printf("</tr>\n");
						}
					}
				?>
			</table>
		</td>
	</tr>
</table>
